import * as actions from '../actions/index';

// 对页面prop 数据进行管理
export const initialState = {
  // 可以升级的权限
  curStep: undefined,
  isLoading: false,
  pageType: 'steps', // steps/records 两个可选则， 一个是记录页， 一个是步骤页,
  // 企业
  isLoadingOrg: false,
  organizations: [],
  selectedOrganizationId: '',
  // 切换企业
  isGoStep1: false,
  // 步骤2的所有库
  allProjects: [],
  // 保存所有页的数据
  allPageProjects: [],
  isLoadingProjects: false,
  // 步骤2选中的ids
  selectedKeys: [],
  // 步骤二选中的项目
  selectedProjects: [],
  // 步骤2搜索条件
  setp1Search: '',
  // 是否同步权限
  sync_member: false,
  step1Pagination: {
    currentPage: 0,
    pageSize: 8,
    total: 0,
  },
  // 步骤三
  // 冲突问题数
  repeatList: [],
  step2Pagination: {
    currentPage: 1,
    pageSize: 8,
  },
  // 提交中
  isUpgrading: false,
  // 升级中
  successList: [],
  failList: [],
  failPagination: {
    currentPage: 1,
    pageSize: 8,
    total: 0,
  },
  successPagination: {
    currentPage: 1,
    pageSize: 8,
    total: 0,
  },
  // 最近一次记录是否请求玩成
  lastUpgradeLoaded: false,
  // 获取进度
  isLoadingProgress: false,
  // 最近一次记录
  lastRecord: {
    CREATED: {
      list: [],
      pageInfo: {
        total: 0,
        pageSize: 8,
        currentPage: 1,
      },
    },
    UNKNOWN_FAILED: {
      list: [],
      pageInfo: {
        total: 0,
        pageSize: 8,
        currentPage: 1,
      },
    },
    SUCCESS: {
      list: [],
      pageInfo: {
        total: 0,
        pageSize: 8,
        currentPage: 1,
      },
    },
  },
  // 所有记录
  isLoadingAllRecords: false,
  allRecords: [],
  allRecordsPagination: {
    currentPage: 1,
    pageSize: 8,
    total: 0,
  },
  recordSearch: '',
  // 企业设置
  groupVisibility: [], // 组可创建
  repoVisibility: [], // 库可创建
  orgSettingLoaded: false,
  // 正在升级
  upgrading: false,
};
const defaultAction = {
  type: 'doNothing',
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    default:
      return state;
  }
}
